{{ define "goods/list.html" }}

{{ template "base/base_header.html" .}}
<head>
	<title>天天生鲜-商品列表</title>
	{{ template "base/base_import.html" .}}
</head>
<body>
	{{ template "base/base_top.html" .}}
	{{ template "base/base_search_car.html" .}}
	{{ template "base/base_goods_type.html" . }}
	
	<div class="breadcrumb">
		<a href="/ttsx/index">全部分类</a>
		<span>></span>
		<a href="/ttsx/goods/list/{{ .GoodsTypeId }}/1?sort={{ .SortType }}">{{ .GoodsTypeName }}</a>
	</div>

	<div class="main_wrap clearfix">
		{{ template "base/base_goods_new.html" .}}

		<div class="r_wrap fr clearfix">
			<div class="sort_bar">
				{{ if eq .SortType "default" }}
					<a href="/ttsx/goods/list/{{ .GoodsTypeId }}/{{ .PageIndex }}?sort=default" class="active">默认</a>
					<a href="/ttsx/goods/list/{{ .GoodsTypeId }}/{{ .PageIndex }}?sort=price" >价格</a>
					<a href="/ttsx/goods/list/{{ .GoodsTypeId }}/{{ .PageIndex }}?sort=sales" >人气</a>
				{{ else if  eq .SortType "price" }}
					<a href="/ttsx/goods/list/{{ .GoodsTypeId }}/{{ .PageIndex }}?sort=default" >默认</a>
					<a href="/ttsx/goods/list/{{ .GoodsTypeId }}/{{ .PageIndex }}?sort=price" class="active" >价格</a>
					<a href="/ttsx/goods/list/{{ .GoodsTypeId }}/{{ .PageIndex }}?sort=sales" >人气</a>
				{{ else if eq .SortType "sales" }}
					<a href="/ttsx/goods/list/{{ .GoodsTypeId }}/{{ .PageIndex }}?sort=default" >默认</a>
					<a href="/ttsx/goods/list/{{ .GoodsTypeId }}/{{ .PageIndex }}?sort=price" >价格</a>
					<a href="/ttsx/goods/list/{{ .GoodsTypeId }}/{{ .PageIndex }}?sort=sales" class="active" >人气</a>
				{{ end }}
			</div>

			<ul class="goods_type_list clearfix">
				{{ range .GoodsList }}
					<li>
						<a href="/ttsx/goods/detail?id={{ .id }}"><img src="{{ .image }}"></a>
						<h4><a href="/ttsx/goods/detail?id={{ .id }}">{{ .name }}</a></h4>
						<div class="operate">
							<span class="prize">￥{{ .price }}</span>
							<span class="unit">{{ .price }}/{{ .unite }}</span>
							<a href="javascript:;" sku_id="{{ .id }}" class="add_goods" id="add_cart" title="加入购物车"></a>
						</div>
					</li>
				{{ end }}
			</ul>
			<div class="pagenation">
				<a href="/ttsx/goods/list/{{ $.GoodsTypeId }}/{{ .StartPage }}?sort={{ $.SortType }}" class="startPage"><上一页</a>
					{{ range $i, $v := .Pages }}
						{{ if eq $v $.PageIndex}}
							<a href="/ttsx/goods/list/{{ $.GoodsTypeId }}/{{ $v }}?sort={{ $.SortType }}" class="active">{{ $v }}</a>
						{{ else }}
							<a href="/ttsx/goods/list/{{ $.GoodsTypeId }}/{{ $v }}?sort={{ $.SortType }}" >{{ $v }}</a>
						{{ end }}
					{{ end }}
				<a href="/ttsx/goods/list/{{ $.GoodsTypeId }}/{{ .NextPage }}?sort={{ $.SortType }}" class="nextPage">下一页></a>
			</div>
		</div>
	</div>

	{{ template "base/base_bottom.html" . }}
	<script type="text/javascript"> 

		$('#add_cart').click(function(){
			// 获取 sku_id 和 count
			sku_id = $(this).attr('sku_id')
			count = 1

			$.ajax({
				url: "/ttsx/cart/add",
				type: "post",
				dataType: "json",
				data: {"sku_id": sku_id, "count": count}
			}).done(function(data){
				if (data.Code == 3) {
					alert("添加购物车成功")
					location.reload()
				}else {
					alert(data.errMsg)
				}
			}).fail(function(){
				alert("请登录后添加")
			})

		})
	</script>
</body>
</html>
{{ end }}